<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h3>我的书架</h3>
        <ul>
            <!-- 循环的时候，必须加 :key="id" -->
            <!-- :key="字符串或数字，且不能重复" -->
            <li v-for="(item, index) in booksList">
            <!-- <li v-for="(item, index) in booksList" :key="item.id"> -->
                <input type="checkbox" name="" id="">
                <span>{{ item.name }}</span>
                <span>{{ item.author }}</span>
                <button @click="delFn(item.id)">删除</button>
            </li>
        </ul>
    </div>

    <!-- 2. 导入vue.js -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                booksList: [
                    { id: 1, name: '《红楼梦》', author: '曹雪芹' },
                    { id: 2, name: '《西游记》', author: '吴承恩' },
                    { id: 3, name: '《水浒传》', author: '施耐庵' },
                    { id: 4, name: '《三国演义》', author: '罗贯中' },
                ]
            },
            methods: {
                delFn(id) {
                    console.log(id)
                    this.booksList = this.booksList.filter(item => {
                        return item.id!== id
                    })
                }
            }
        })
    </script>
</body>
</html>